import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/utils/image_utils.dart';
import 'package:flutter_demo/core/common/values/gaps.dart';
import 'package:flutter_demo/core/common/values/server.dart';
import 'package:flutter_demo/core/typeof/function.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class TitleWidget extends StatelessWidget {
  String? titleImage;
  String? buttonTitle;
  String title;

  TitleWidget({required this.title, this.buttonTitle, this.titleImage});

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Wrap(
          children: [
            if (titleImage != null)
              //原型裁剪
              ClipOval(
                child: Container(
                  alignment: Alignment.center,
                  width: 25.w,
                  height: 25.h,
                  //背景颜色
                  color: Colors.orange,
                  // .withOpacity(0.05),
                  child: Image.asset(
                    ImageUtils.getImagePath(titleImage ?? ""),
                    color: Colors.white,
                    width: 18.w,
                    height: 18.h,
                  ),
                ),
              ),
            if (titleImage != null) Gaps.hGap4,
            SizedBox(
              width: 240.w,
              child: Text(
                title,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(color: Colors.black, fontSize: 20),
              ),
            ),
          ],
        ),
        if (buttonTitle != null)
          SizedBox(
            height: 25.h,
            child: elementButtonWidget(buttonTitle, onPressed: () {}),
          ),
      ],
    );
  }
}

/**
 * 自定义通用按钮
 */
Widget elementButtonWidget(String? title, {ParamVoidCallback? onPressed}) {
  if (title == null) return Gaps.empty;
  final theme = Get.theme;
  return MaterialButton(
    onPressed: () {
      if (onPressed == null) {
        logger.i("通用按钮被点击了");
        //RouteUtils.routeFromActionStr(elementButton.action);
      } else {
        onPressed.call();
      }
    },

    height: 24.h,
    color: Colors.transparent,
    //按钮点击下的颜色
    highlightColor: theme.hintColor,

    //按钮的阴影
    elevation: 0,
    padding: const EdgeInsets.all(0),
    minWidth: 40.h,
    focusElevation: 0,

    ///按钮按下时的阴影高度
    highlightElevation: 0,

    ///用来设置按钮的边框的样式
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.r),
        side: BorderSide(
          color: theme.hintColor,
        )),
    child: Row(children: [
      Gaps.hGap12,
      //标题前图片
      // Image.asset(ImageUtils.getImagePath('icon_play_small'),
      //     color: theme.iconTheme.color, width: 12.w, height: 12.h),
      Text(
        title.toString(),
        style: TextStyle(fontSize: 12.sp, color: theme.iconTheme.color),
      ),
      Image.asset(ImageUtils.getImagePath('icon_more'),
          color: theme.iconTheme.color, width: 12.h, height: 12.h),
      Gaps.hGap10,
    ]),
  );
}
